{include file="header.tpl"}
<div class="page-title">トランザクション</div>
    <div style="width: 100%; float: left; position: relative;">
        
        <div class="x-scroll">
            <form class="transaction_search" method="GET">
                <div class="submit-buttons">
                    <button type="submit" class="button-success pure-button">検索</button>
                    <a href="transactions.php"><button type="button" class="button-success pure-button">クリア</button></a>
                </div>
                
                <table class="manage_table">
                    <thead> 
                        <tr>
                            <th>ID</th>
                            <th>管理番号</th>
                            <th>物件名</th>
                            <th>号室</th>
                            <th>退去者</th>
                            <th>連絡先</th>
                            <th>保証会社</th>
                            <th class="date-column">内容</th> <!-- noi dung-->
                            <th class="date-column">受理日 </th> <!--  ngày tiếp nhận xử lý-->
                            <th class="date-column">解約日</th><!-- ngày hủy hợp đồng-->
                            <th class="date-column">退去日</th><!-- ngày trả phòng-->
                            <th>時間</th>  <!-- thời gian-->
                            <th>立会内装業者</th><!--cty sửa chữa phòng-->
                            <th>内見方法</th><!--phương pháp xem phòng-->
                            <th class="date-column">報告書</th><!--  văn bản báo cáo chi phí-->
                            <th class="date-column">発注</th><!--  chấp thuận báo cáo-->
                            <th class="date-column">内装ＵＰ</th><!-- sữa chữa nội thất-->
                            {if $viewer_type != 3}
                                <th>鍵交換業者</th><!-- cty thay chìa khóa-->
                                <th class="date-column">交換予定日</th><!-- ngày dự định thay chìa-->
                                <th class="date-column">鍵交換日</th><!--   ngày thay chìa khóa-->
                            {/if}
                            <th class="date-column">回収</th><!-- phục hồi-->
                            <th class="date-column">賃発日</th><!-- ngày xuất tiền-->
                            <th  class="date-column">申込</th><!--  đăng ký-->
                            <th>新契約番号</th><!--  mã số hợp đồng mới-->
                            <th>備考</th><!--  tham khảo-->
                            {if $viewer_type == 1}
                                <th class="date-column">弁済期限</th><!--  thời hạn thanh toán-->
                                <th class="date-column">弁済請求日</th><!-- ngày yêu cầu thanh toán-->
                                <th>清算</th><!--  thanh toán-->
                            {/if}
                            <th>ステータス</th>
                            <th>活動</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="filter_elements">
                            <td></td>
                            <td>
                                <input name='contract_code' id="contract_code" type="text" class="search" placeholder="管理番号 ..." value="{$params.contract_code}">
                            </td>
                            <td>
                                <input name='house_name' id="house_name" type="text" class="search" placeholder="物件名 ..." value="{$params.house_name}">
                            </td>
                            <td>
                                <input name='room_number' id="room_number" type="text" class="search" placeholder="号室 ..." value="{$params.room_number}">
                            </td>
                            <td>
                                <input name='client_name' id="client_name" type="text" class="search" placeholder="退去者 ..." value="{$params.client_name}">
                            </td>
                            <td>
                                <input name='client_phone' id="client_phone" type="text" class="search" placeholder="連絡先 ..." value="{$params.client_phone}">
                            </td>
                            <td>
                                <input name='guarantee_company_name' id="guarantee_company_name" type="text" class="search" placeholder="保証会社 ..." value="{$params.guarantee_company_name}">
                            </td>
                            <td>
                                <select name="content_id" id="content_id">
                                    <option value="0">  </option>
                                    {foreach from=$contents key=k item=c}
                                        <option value="{$c.id}" {if $params.content_id eq $c.id} selected = "selected" {/if}>{$c.name}</option>
                                    {/foreach}
                                </select>
                            </td>
                            <td>
                                <input class='date-selector' name='reception_date' id="reception_date" type="text"  value="{$params.reception_date}">
                            </td>
                            <td>
                                <input name='contract_cancel_date' id="contract_cancel_date" type="text" class='date-selector'  value="{$params.contract_cancel_date}">
                            </td>
                            <td>
                                <input name='stop_renting_date' id="stop_renting_date" type="text" class='date-selector'  value="{$params.stop_renting_date}">
                            </td>
                            <td>
                                <input name='stop_renting_time' id="stop_renting_time" type="text"  value="{$params.stop_renting_time}">
                            </td>
                            <td>
                                <select name="room_partner_id" id="room_partner_id" title="cty sửa chữa phòng">
                                    <option value="0">  </option>
                                    {foreach from=$repair_users key=k item=u}
                                        <option value="{$u.id}" {if $params.room_partner_id eq $u.id} selected = "selected" {/if}>{$u.user_lname} {$u.user_fname}</option>
                                    {/foreach}
                                </select>
                            </td>
                            <td>
                                <input name='way_to_see_room' id="way_to_see_room" type="text" class="search" placeholder="内見方法 ..."  value="{$params.way_to_see_room}">
                            </td>
                            <td>
                                <input name='report_fee_text' id="report_fee_text" type="text" class='date-selector' value="{$params.report_fee_text}">
                            </td>
                            <td>
                                <input name='accept_report_fee' id="accept_report_fee" type="text" class='date-selector' value="{$params.accept_report_fee}">
                            </td>
                            <td>
                                <input name='funiture_repair' id="funiture_repair" type="text" class='date-selector' value="{$params.funiture_repair}">
                            </td>
                            {if $viewer_type != 3}
                                <td>
                                    <select name="key_partner_id" id="room_partner_id" title="cty sửa chia khoa">
                                        <option value="0">  </option>
                                        {foreach from=$key_users key=k item=u}
                                            <option value="{$u.id}" {if $params.key_partner_id eq $u.id} selected = "selected" {/if}>{$u.user_lname} {$u.user_fname}</option>
                                        {/foreach}
                                    </select>
                                </td>
                                <td>
                                    <input name='appointment_change_key_date' id="appointment_change_key_date" type="text" class='date-selector' value="{$params.appointment_change_key_date}">
                                </td>
                                <td>
                                    <input name='assign_key_date' id="assign_key_date" type="text" class='date-selector' value="{$params.assign_key_date}">
                                </td>
                            {/if}
                            <td>
                                <input name='recovery_key_date' id="recovery_key_date" type="text" class='date-selector' value="{$params.recovery_key_date}">
                            </td>
                            <td>
                                <input name='new_money_date' id="new_money_date" type="text" class='date-selector' value="{$params.new_money_date}">
                            </td>
                            <td>
                                <input name='new_registry_date' id="new_registry_date" type="text" class='date-selector' value="{$params.new_registry_date}">
                            </td><!-- ngay xuat tien -->
                            <td>
                                <input name='new_registry_content' id="new_registry_content" type="text" class="search" placeholder="新契約番号 ..." value="{$params.new_registry_content}">
                            </td>
                            <td>
                                <input name='new_registry_comment' id="new_registry_comment" type="text" class="search" placeholder="備考 ..." value="{$params.new_registry_comment}">
                            </td>
                            {if $viewer_type == 1}
                                <td>
                                    
                                </td>
                                <td>
                                    <input name='payment_request_date' id="payment_request_date" type="text" class='date-selector' value="{$params.payment_request_date}">
                                </td>
                                <td>
                                    <input name='payment' id="payment" type="text" class="search" placeholder="清算 ..." value="{$params.payment}">
                                </td>
                            {/if}
                            <td>
                                <select name="status" id="status">
                                    <option value=""> </option>
                                    <option value="processing" {if $params.status eq 'processing'} selected = "selected" {/if} >Processing</option>
                                    <option value="completed" {if $params.status eq 'completed'} selected = "selected" {/if} >Completed</option>
                                </select>
                            </td>
                            <td class="manage_table_options">
                                
                            </td>
                        </tr>
                        {if count($transactions)}
                            {foreach from=$transactions key=k item=transaction}
                            <tr>
                                <td>{$transaction.id}</td>
                                <td>{$transaction.contract_code}</td>
                                <td>{$transaction.house_name}</td>
                                <td>{$transaction.room_number}</td>
                                <td>{$transaction.client_name}</td>
                                <td>{$transaction.client_phone}</td>
                                <td>{$transaction.guarantee_company_name}</td>
                                <td>{$transaction.content_name}</td>
                                <td>{$transaction.reception_date}</td>
                                <td>{$transaction.contract_cancel_date}</td>
                                <td>{$transaction.stop_renting_date}</td>
                                <td>{$transaction.stop_renting_time}</td>
                                <td>
                                    {$repair_user = $user->getAccountById($transaction.room_partner_id) }
                                    {if !empty($repair_user)}
                                        {$repair_user.user_lname} {$repair_user.user_fname}
                                    {/if}
                                </td>
                                <td>{$transaction.way_to_see_room}</td>
                                <td>{$transaction.report_fee_text}</td>
                                <td>{$transaction.accept_report_fee}</td>
                                <td>{$transaction.funiture_repair}</td>
                                {if $viewer_type != 3}
                                    <td>
                                        {$key_user = $user->getAccountById($transaction.key_partner_id) }
                                        {if !empty($key_user)}
                                            {$key_user.user_lname} {$key_user.user_fname}
                                        {/if}
                                    </td>
                                    <td>{$transaction.appointment_change_key_date}</td>
                                    <td>{$transaction.assign_key_date}</td>
                                {/if}
                                <td>{$transaction.recovery_key_date}</td>
                                <td>{$transaction.new_registry_date}</td>
                                <td></td><!-- ngay xuat tien -->
                                <td>{$transaction.new_registry_content}</td>
                                <td>{$transaction.new_registry_comment}</td>
                                {if $viewer_type == 1}
                                    <td>
                                        {if !empty($transaction.payment_day_number) && !empty($transaction.contract_cancel_date)}
                                            {date('Y-m-d',  strtotime("`$transaction.contract_cancel_date` + `$transaction.payment_day_number` days"))}
                                        {/if}
                                    </td>
                                    <td>{$transaction.payment_request_date}</td>
                                    <td>{$transaction.payment}</td>
                                {/if}
                                <td>{$transaction.status}</td>
                                <td class="manage_table_options">
                                    {if $viewer_type == 1 || $user->user_info['id'] == $transaction.room_partner_id ||$user->user_info['id'] == $transaction.key_partner_id }
                                        <a href="edit_transaction.php?id={$transaction.id}">編集</a>   
                                        <!--|<a href="transaction.php?id={$transaction.id}">詳細</a>-->
                                    {/if}
                                    {if $can_delete}
                                        | <a href="delete_transaction.php?id={$transaction.id}">削除</a>   
                                    {/if}
                                </td>
                            </tr>
                            {/foreach}
                        
                        {/if}
                    </tbody>
                </table>
            </form>
        </div>
        {if count($transactions)}
            <center>
                ページ:
                {for $i=1 to $totalPage }
                {if $i eq $page_number}<span style="margin-left: 10px; color: red;">[{$i}]</span>{else}<a href="transactions.php?page_number={$i}{foreach from=$params key=k item=v}{if !empty($v) && $k != 'page_number'}&{$k}={$v}{/if}{/foreach}" 
                style='margin-left: 10px;color: black;'>{$i}{/if}</a>
                {/for}
            </center>
        {else}
            <ul class="form-notices">
                <li>No transaction</li>
            </ul>
        {/if}
    </div>
    {literal}
        <script type="text/javascript">
            $(function() {
                $( ".date-selector" ).datepicker({ dateFormat: 'yy-mm-dd',appendText: "(yyyy-mm-dd)",constrainInput: false});
                $('#stop_renting_time').timepicker({ timeFormat: "hh:mm:ss",constrainInput: false});
//                $( ".date-selector" ).each(function() {
//                    if(this.value == 'blank'){
//                        this.style.color = "red";
//                        this.style.borderColor = "red";
//                    }
//                  });
              });
        </script>
    {/literal}
{include file="footer.tpl"}